#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define N 20

int main(void)
{
    int arr[N];
    srand(time(NULL));

    int min_i = 0, max_i = 0;

    for (int i = 0; i < N; i++){
        arr[i] = rand() % 1000;
        printf("%d ", arr[i]);

        if (arr[min_i] > arr[i])
            min_i = i; // 记录最小值的下标
        if (arr[max_i] < arr[i])
            max_i = i; // 记录最大值的下标
    }
    printf("\n");

    /* 交换位置 */
    int temp = arr[min_i];
    arr[min_i] = arr[max_i];
    arr[max_i] = temp;

    /* 输出打印 */
    for (int i = 0; i < N; i++)
        printf("%d ", arr[i]);

    printf("\n");
    return 0;
}
